

var maxDepth = function (root) {
    if (root === null) {
        return 0;
    }
    let leftHeight = maxDepth(root.left)
    let rightHeight = maxDepth(root.right)
    let maxHeight = 1 + Math.max(leftHeight, rightHeight)
    return maxHeight;
};

var maxDepth = function (root) {
    // 思路：采用后序遍历，遍历到叶子节点，然后不断把深度向上返回
    if (!root) return 0;

    let leftHeight = maxDepth(root.left);
    let rightHright = maxDepth(root.right);
    let maxHeight = 1 + Math.max(leftHeight, rightHright);
    return maxHeight;
}